package com.pro.back.controller;

import com.pro.back.bean.Device;
import com.pro.back.bean.DeviceType;
import com.pro.back.bean.bo.DeviceAdd;
import com.pro.back.bean.bo.DeviceAddInfo;
import com.pro.back.bean.bo.RepairInfo;
import com.pro.back.bean.common.ApiRes;
import com.pro.back.bean.po.DeviceAddDto;
import com.pro.back.bean.po.DevicePO;
import com.pro.back.service.DeviceService;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: jingwenjuan
 * @Description:
 * @Date: 2025-04-19
 */
@RestController
@RequestMapping("/device")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    @ApiOperation("查询所有的设备类型")
    @GetMapping("/selectDeviceType")
    public ApiRes selectDeviceType() {
        return deviceService.selectDeviceType();
    }

    @ApiOperation("新增设备类型")
    @PostMapping("/insertDeviceType")
    public ApiRes insertDeviceType (@RequestBody DeviceType type) {
        return deviceService.insertDeviceType(type);
    }

    @ApiOperation("删除设备类型")
    @GetMapping("/delDeviceType")
    public ApiRes delDeviceType(Long id) {
        return deviceService.delDeviceType(id);
    }

    @ApiOperation("分页条件查询所有的设备")
    @PostMapping("/selectAllDevice")
    public ApiRes selectAllDevice(@RequestBody DevicePO po ) {
        return deviceService.selectAllDevice(po);
    }

    @ApiOperation("新增设备")
    @PostMapping("/insertDevice")
    public ApiRes insertDevice(@RequestBody Device device) {
        return deviceService.insertDevice(device);
    }

    @ApiOperation("根据设备id编辑设备")
    @PostMapping("/updateDevice" )
    public ApiRes updateDevice(@RequestBody Device device) {
        return deviceService.updateDevice(device);
    }

    @ApiOperation("删除设备")
    @GetMapping("/delDevice")
    public ApiRes delDevice(Long id) {
        return deviceService.delDevice(id);
    }

//    设备采购申请记录分页查询
    @ApiOperation("分页条件查看设备采购申请记录")
    @PostMapping("/selectAllDeviceAdd")
    public ApiRes selectAllDeviceAdd(@RequestBody DeviceAddDto dto) {
            return deviceService.selectAllDeviceAdd(dto);
    }

    @ApiOperation("新增设备采购申请")
    @PostMapping("/insertDeviceAdd")
    public ApiRes insertDeviceAdd(@RequestBody DeviceAdd add ) {
        return deviceService.insertDeviceAdd(add);
    }


    @ApiModelProperty("删除设备采购申请")
    @GetMapping("/delDeviceAdd")
    public ApiRes delDeviceAdd(@RequestParam Long id) {
        return deviceService.delDeviceAdd(id);
    }

    @ApiOperation("设备入库登记")
    @PostMapping("/insertDeviceInfo")
    public ApiRes insertDeviceInfo(@RequestBody DeviceAddInfo info) {
        return deviceService.insertDeviceInfo(info);
    }

    @ApiOperation("根据设备采购id查看入库信息")
    @GetMapping("/selectDeviceInfoByAdd")
    public ApiRes selectDeviceInfoByAdd(@RequestParam("id") Long id) {
        return deviceService.selectDeviceInfoByAdd(id);
    }

//    -------维修记录
    @ApiOperation("新增维修记录")
    @PostMapping("/insertRepairInfo")
    public ApiRes insertRepairInfo(@RequestBody RepairInfo info) {
        return deviceService.insertRepairInfo(info);
    }


    @ApiOperation("根据维修id查看维修信息")
    @GetMapping("/selectByRepairId")
    public ApiRes selectByRepairId(@RequestParam("id") Long id) {
        return deviceService.selectByRepairId(id);
    }


    @ApiOperation("设备检修申请信息excel导出")
    @GetMapping("/exportRepair")
    public ApiRes exportRepair(HttpServletResponse response) throws IOException {
        return deviceService.exportRepair(response);
    }

    @ApiOperation("设备报废excel导出")
    @GetMapping("/exportDelDevice")
    public ApiRes exportDelDevice(HttpServletResponse response) throws IOException {
        return deviceService.exportDelDevice(response);
    }

}


